#include <vector>
using namespace std;
vector<int> searchRange(vector<int> &nums, int target) {
  int left = 0;
  int right = nums.size() - 1;
  int mid = -1;
  int start = -1;
  int end = -1;
  while (left <= right) {
    mid = (left + right) / 2;
    if (nums[mid] == target) {
      start = mid;
      end = mid;
      break;
    }
    if (nums[mid] < target) {
      right = mid + 1;
    } else {
      left = mid - 1;
    }
  };
  if (start == -1) {
    return {-1, -1};
  }
  // 范围查找
  bool flag = true;
  while (flag) {
    flag = false;
    if (start - 1 >= 0 && nums[start - 1] == target) {
      start--;
      flag = true;
    }
    if (end + 1 < nums.size() && nums[end + 1] == target) {
      end++;
      flag = true;
    }
  }
  return {start, end};
}